<?php
/**
 * Author: DRERY <rui1642@foxmail.com>
 */

/**
 * @var $list \common\models\Statistics[]
 * @var $this \yii\web\View
 */
\yii\bootstrap\BootstrapAsset::register($this);
\yii\web\JqueryAsset::register($this);
$CSS = <<<CSS
thead{
    position: fixed;
    top: 0;
    z-index: 99;
    background: #FFFFFF;
}
CSS;


$JS = <<<JS
$('thead').children('tr').children('td').each(function(index) {
    if (index == 0) {
        $(this).width($('.data-region').width());
    } else if (index == 4) {
        $(this).width($('.data-tcom').width());
    } else if (index == 5) {
        $(this).width($('.data-ecom').width());
    } else if (index == 6) {
        $(this).width($('.data-tveh').width());
    } else if (index == 7) {
        $(this).width($('.data-eveh').width());
    } else if (index == 8) {
        $(this).width($('.data-temp').width());
    } else if (index == 9) {
        $(this).width($('.data-eemp').width());
    }
});

headHeight = $('thead').height();
$('.blank').height(headHeight - 4);
JS;

//$this->registerCss($CSS);
//$this->registerJs($JS);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html >
<html>
    <head>
        <meta charset="<?= Yii::$app->charset ?>">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="renderer" content="webkit">
        <meta http-equiv="Cache-Control" content="no-siteapp"/>
        <title>各县市区运输公司统计表</title>
        <?php $this->head() ?>
        <style>
            img{
                max-width: 100%;
            }
        </style>
    </head>
    <body style="max-width: 640px;margin: auto;">
    <?php $this->beginBody() ?>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <td rowspan="2" align="middle" style="line-height: 50px;">&nbsp;</td>
                    <td colspan="2" align="middle">运输公司</td>
                    <td colspan="2" align="middle">营运车辆</td>
                    <td colspan="2" align="middle">从业人员</td>
                </tr>
                <tr align="middle">
                    <td>实有数量</td>
                    <td>注册数量</td>
                    <td>实有数量</td>
                    <td>注册数量</td>
                    <td>实有数量</td>
                    <td>注册数量</td>
                </tr>
            </thead>
            <tbody>
                <!--<tr class="blank">
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>-->
            <?php foreach ($list as $stat) :?>
                <tr align="right">
                    <td class="data-region" align="left" style="font-weight: bold"><?=$stat->region?></td>
                    <td class="data-tcom"><?=$stat->company_count?></td>
                    <td class="data-ecom"><?php count($stat->companys)?></td>
                    <td class="data-tveh"><?=$stat->vehicle_count?></td>
                    <td class="data-eveh">
                        <?= $stat->companys ? array_reduce($stat->companys, function($re, $item) {
                            return count($item->vehicles) + $re;
                        }) : 0?>
                    </td>
                    <td class="data-temp"><?=$stat->employee_count?></td>
                    <td class="data-eemp">
                        <?= $stat->companys ? array_reduce($stat->companys, function($re, $item) {
                            return count($item->users) + $re;
                        }) : 0?>
                    </td>
                </tr>
                <?php if(!empty($stat->companys)) :?>
                    <?php foreach ($stat->companys as $company) :?>
                        <tr align="right">
                            <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;<?=$company->name?></td>
                            <td class="data-tcom">&nbsp;</td>
                            <td class="data-ecom">1</td>
                            <td class="data-tveh">&nbsp;</td>
                            <td class="data-eveh"><?=count($company->vehicles)?></td>
                            <td class="data-temp">&nbsp;</td>
                            <td class="data-eemp"><?=count($company->users)?></td>
                        </tr>
                    <?php endforeach;?>
                <?php endif;?>
            <?php endforeach;?>
            </tbody>
        </table>
    <?php $this->endBody() ?>
    </body>
</html>
<?php $this->endPage() ?>